<?php

/* ------------------------------------------ *\
 * Explay CMS 3.0                             *
 * Copyright © Golovdinov Alexander 2008-2009 *
 * License: GNU GPL v.3                       *
 * http://explay.su                           *
\* ------------------------------------------ */

header ("Cache-control: no-cache");

define ('START_TIME', microtime (true));

session_start ();
ob_start ();

/* -------------------------- */
   error_reporting (E_ALL);
   ini_set ('display_errors', 1);
/* -------------------------- */

mb_internal_encoding('utf-8');
 
define ('HTTP_HOST', 'http://' . $_SERVER['HTTP_HOST']);
define ('DOC_ROOT', str_replace ('\\', '/', rtrim (dirname (__FILE__), '/')));
define ('ENGINE_ROOT', DOC_ROOT . '/explay');

$g_langCollection = array ();

include ENGINE_ROOT . '/error_handlers.php';
include ENGINE_ROOT . '/DBConfig.php';
include ENGINE_ROOT . '/config.php';
include ENGINE_ROOT . '/functions.php';
include ENGINE_ROOT . '/XSLTFunctions.php';
include ENGINE_ROOT . '/classes/exceptions/all_exceptions.php';

// Сектретный-секретный код
if (isset ($_SESSION['scode'])) {
	$scode = $_SESSION['scode'];
} else {
	$_SESSION['scode'] = $scode = createHash (8);
}
define ('SCODE', $scode);

// Свой mod_rewrite
rewriteURI ();

// Инициализация базы данных
DBController::getInstance()->loadEngine (DB_TYPE);

define ('CORE_LIFETIME', Regedit::getInstance()->get ('//settings/cache/core_lifetime'));

// Инициализация кеш-контроллера
CacheController::getInstance()->loadEngine (CACHE_ENGINE);

// Инициализация юзверя
ExplaySession::init ();

// Инициализация протоколов
stream_wrapper_register ('lang', 'LangStream');
stream_wrapper_register ('xmodule', 'XMLStream');
stream_wrapper_register ('xobject', 'XMLStream');

// Инициализация форматов
$pageParser = PageParser::getInstance ();
$pageParser->addFormatTranslator ('html', 'XSLTranslator', true);
$pageParser->addFormatTranslator ('xml', 'XMLTranslator');
$pageParser->addFormatTranslator ('rss', 'RSSTranslator');

if (getRequest ('force_format', 'bool')) {
	$pageParser->setCurrentFormat (getRequest ('force_format'));
}

// run!
$cmsController = CMSController::getInstance ();
$cmsController->GSpot ();

exitCMS ();

function exitCMS () {
	die ("\r\n<!-- " . DBController::getCountQueries() . " | " . round (microtime (true) - START_TIME, 5) . " -->");
}